#include <mutex>
#include <iostream>

class Widget
{
public:
   static Widget* GetInstance()
   {
      if (_instance == nullptr)
      {
	 _mutex.lock();
      	 if (_instance == nullptr) {
      	    _instance = new Widget();
      	 }
      	 _mutex.unlock();
      }
      return _instance;
   }

   ~Widget()
   {
      std::cout << "~Widget()" << std::endl;
   }

private:
   Widget()
   {
      std::cout << "Widget()" << std::endl;
   }

   Widget(const Widget&) = delete;
   Widget operator=(const Widget&) = delete;

private:
   std::mutex _mutex;

private:
   static Widget* _instance;
};

Widget* Widget::_instance = nullptr;
